package com.lq.educationsystem.socre.controller;


import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.ScorePageVo;
import com.lq.educationsystem.common.vo.SubjectStudentScoreVo;
import com.lq.educationsystem.socre.entiy.ScoreTb;
import com.lq.educationsystem.socre.service.ScoreBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "考试信息")
@RequestMapping("/score/base")
@RestController
public class ScoreBaseController {
    //增加

    @Autowired
    ScoreBaseService scoreBaseService;

    @Operation(summary = "插入分数信息")
    @PostMapping("/insert")
    public Result insertInfo(@RequestBody ScoreTb scoreInofo) {
        scoreBaseService.insertInfo(scoreInofo);
        return ResultBuild.buildOk();
    }


    //删除
    @Operation(summary = "通过id删除分数信息")
    @PostMapping("/delete")
    public Result deleteById(@RequestBody ScoreTb scoreInofo) {
        Integer scoreId = scoreInofo.getScoreId();
        //删除
        scoreBaseService.deleteById(scoreId);
        return ResultBuild.buildOk();

    }

    //更新
    @Operation(summary = "跟新分数信息")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody ScoreTb scoreInofo) {
        scoreBaseService.updateInfo(scoreInofo);
        return ResultBuild.buildOk();
    }

    //通过id查询
    @Operation(summary = "通过id查询分数信息")
    @PostMapping("/querybyid")
    public Result<ScoreTb> queryById(@RequestBody ScoreTb scoreInofo) {
        //获取主键
        Integer scoreId = scoreInofo.getScoreId();
        //通过id查询
        Result result = scoreBaseService.queryById(scoreId);

        return result;
    }

    //    查询
    @Operation(summary = "分页查询")
    @PostMapping("/query")
    public ResultPage<ScoreTb> queryList(@RequestBody ScorePageVo scorePageVo) {
        //查询数据
        ResultPage<ScoreTb> scoreTbResultPage = scoreBaseService.queryList(scorePageVo);
        return scoreTbResultPage;

    }

    //通过课程集合查询和学生id查询学生的分数
    @Operation(summary = "查询学生分省通过课程id和学生id")
    @PostMapping("/query/student/score")
    public ResultPage<ScoreTb> queryStudentScoreBySubjectIdAndStudentId(@RequestBody List<Integer> subjectIdList, @RequestParam("studentId") Integer studentId) {
        ResultPage<ScoreTb> scoreTbResultPage = scoreBaseService.queryStudentScoreBySubjectIdAndStudentId(subjectIdList, studentId);
        return scoreTbResultPage;
    }

    //通过学生id集合和课程id查询当前科目内所有学生的分数
    @Operation(summary = "查询学生课程分数通过学生id")
    @PostMapping("/query/subject/student/score")
    public ResultPage<ScoreTb> querySubjectStudentScoreByStudentId(@RequestBody List<Integer> studentIdInfoList, @RequestParam("subjectId") Integer subjectId) {
        ResultPage<ScoreTb> scoreTbResultPage = scoreBaseService.querySubjectStudentScoreByStudentId(studentIdInfoList, subjectId);
        return scoreTbResultPage;
    }


    //通过学生id集合 和课程id 批量添加数据
    @Operation(summary = "通过学生id和课程id批量添加学生分数")
    @PostMapping("/query/student/subject/socre")
    public Result<ScoreTb> addSubjectStudentScoreByStudentIdAndSubjectId(@RequestBody List<Integer> studentIdInfoList, @RequestParam("subjectId") Integer subjectId) {
        Result<ScoreTb> scoreTbResultPage = scoreBaseService.addSubjectStudentScoreByStudentIdAndSubjectId(studentIdInfoList, subjectId);
        return scoreTbResultPage;
    }

    //分数修改
    @Operation(summary = "通过学生id和课程id修改分数")
    @PostMapping("update/student/score")
    public Result updateStudentScoreByStudentIdAndSubjectId(@RequestBody SubjectStudentScoreVo subjectStudentScoreVo) {
        Result result = scoreBaseService.updateStudentScoreByStudentIdAndSubjectId(subjectStudentScoreVo);
        return result;
    }
}
